package com.zhouwr.common.datasource.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @program: zhouwr-cloud
 * @description: MyBatisPlus配置
 * @author: zhouwr
 * @create: 2020-10-05 10:34
 * @version：1.0
 **/
@EnableTransactionManagement
@Configuration
@MapperScan("com.zhouwr.**.mapper")
public class MybatisPlusConfig {
    /**
     * SQL执行效率插件
     */
    @Bean
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor()
                .setFormat(true)//参数：format SQL SQL是否格式化，默认false
                .setMaxTime(1000);//参数：maxTime SQL 执行最大时长，超过自动停止运行，有助于发现问题。
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}
